/**
 * @returns {TaskFactory}
 */
function TaskFactory()
{
	this.fillPlotArray = function(dataResult)
	{
		var plot_array=[];

		jQuery.each(dataResult, function( index, value ) {
			//console.log( value.title );
			//console.log( value.listAverage );
			if(typeof value.listAverage != "undefined" && value.listAverage.length>0)
			{
				plot_array.push(value.listAverage);
			}
		});

		return plot_array; 
	};
	
	this.getSpeed = function(dataResult)
	{
		var plot_array=[];
		
		jQuery.each(dataResult, function( index, value ) {
			// each scenario:
			if(typeof value.listAverage != "undefined" && value.listAverage.length>0)
			{
				var speed_array=[];
				var previous_value = 0;
				jQuery.each(value.listAverage, function( j, avg ) {
					   // each average for this scenario
					   current_speed=avg*(j+1)-(j*previous_value);					   
					   speed_array.push(current_speed);
					   previous_value=avg;
					
				});
				plot_array.push(speed_array);
				
			}
			
		});

		return plot_array; 
	};

	/*
	 * Return the task id. 
	 */
	this.getTaskId = function(szJobName)
	{
		jQuery.ajax({
			url : "./testGetTaskId-"+szJobName+".json",
			type: "GET",
			async: false,
			dataType : "json"
		})

		.done(function(data) {
			if(data.taskId)
			{
				taskId =data.taskId;		
			}
			return true;
		})
		.fail(function() {
			return false;
		});

		return taskId;
	};	


	this.loadTask = function(szJobName, taskId)
	{
		var dataResult=undefined;
		jQuery.ajax({
			url : "./testLoadTask-"+szJobName+"-"+taskId+".json",
			type: "GET",
			async: false,
			dataType : "json"
		})

		.done(function(data) {
			dataResult = data;
			return true;
		})
		.fail(function() {
			return false;
		})
		;		

		return dataResult;
	};
	
	this.getJsonResult = function(szUrl)
	{
		var dataResult=undefined;
		jQuery.ajax({
			url : szUrl,
			type: "GET",
			async: false,
			dataType : "json"
		})

		.done(function(data) {
			dataResult = data;
			return true;
		})
		.fail(function() {
			return false;
		})
		;		

		return dataResult;
	};
	
}